package com.code.leetcode.before50;

import java.util.ArrayList;
import java.util.List;

/**
 * @author codeDorado
 * @version 1.0
 * @date 2020/7/24 17:02
 */
public class The78 {
    List<List<Integer>> lists = new ArrayList<>();
    int len, k;

    public void backtrack(int index, List<Integer> list, int[] nums) {
        if (k == list.size()) {
            lists.add(new ArrayList(list));
        }
        for(int i = index; i < len; i++) {
            list.add(nums[i]);
            backtrack(i + 1, list, nums);
            list.remove(list.size() - 1);
        }
    }

    public List<List<Integer>> subsets(int[] nums) {
        len = nums.length;
        for(k = 0; k < len + 1; k++) {
            backtrack(0, new ArrayList(), nums);
        }
        return lists;
    }
}
